package com.zcup.designer.contribute.iterator;

import org.junit.jupiter.api.Test;

/*
    迭代器模式
 */
public class IterTest {
    @Test
    public void test(){
        ConcreteAggregate ca2 = new ConcreteAggregate();

        ConcreteAggregate ca = new ConcreteAggregate();

        ca.setItem(0,"大鸟");
        ca.setItem(1,"菜鸟");
        ca.setItem(2,"行李");
        ca.setItem(3,"樱花");
        ca.setItem(4,"老人");
        ca.setItem(5,"金融");

        ca2.setItem(0,"test");

        Iterator iterator = ca.createIterator();
        // Iterator iterator2 = new ConcreteIterator(ca2);
        Iterator iterator2 = ca2.createIterator();
        // Object first = iterator.first();
        // System.out.println(first);
        while (!iterator.isEnd()){
            System.out.println(iterator.next() + "请买票");
        }
        while (!iterator2.isEnd()){
            System.out.println(iterator2.next() + "请买票");
        }
    }
}
